package javasql;

import java.sql.*;
import java.util.Date;
import java.util.Scanner;

public class Jdbc7 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String url = "jdbc:mysql://localhost:3306/kgb762?useSSL=false";
        Connection conn = null;
        PreparedStatement st = null;
        try {
            conn = DriverManager.getConnection(url, "root", "123456");
            System.out.println(conn.getClass().getName());
            System.out.println("链接已经建立");
            Scanner input=new Scanner(System.in);
            System.out.println("请输入姓名：");
            String  sname=input.nextLine();
            System.out.println("请输入性别：");
            String  sex =input.nextLine();
            System.out.println("请输入电话：");
            String  telephone=input.nextLine();
            System.out.println("请输入QQ号");
            String  qq=input.nextLine();
            System.out.println("请输入微信号");
            String  wechat=input.nextLine();
            System.out.println("请输入年级");
            int gradeid =input.nextInt();
            System.out.println("请输入入学日期");
            String enterdate =input.nextLine();
           System.out.println("请输入从那个城市来");
            String  fromcity=input.nextLine();
            System.out.println("请输入出生日期");
            String birthday = input.nextLine();
            System.out.println("请输入地址");
            String address = input.nextLine();
            System.out.println("请输入密码");
            String pass = input.nextLine();
            String sql = " INSERT INTO `s_student` (`sname`, `sex`, `telephone`, `qq`, `wechat`, `gradeid`, `enterdate`, `fromcity`, `birthday`, `address`, `pass`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );";
            System.out.println(sql);
            st = conn.prepareStatement(sql);
            st.setString(1,sname);
            st.setString(2,sex);
            st.setString(3,telephone);
            st.setString(4,qq);
            st.setString(5,wechat);
            st.setInt(6,gradeid);
            st.setString(7,enterdate);
            st.setString(8,fromcity);
            st.setString(9,birthday);
            st.setString(10,address);
            st.setString(11,pass);
            int num = st.executeUpdate();
            System.out.printf("添加了",num,"数据");
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                st.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
